//
//  UIButton+LT.m
//  Teacher
//
//  Created by 刘涛 on 16/1/23.
//  Copyright © 2016年 jevictek. All rights reserved.
//

#import "UIButton+LT.h"

@implementation UIButton (LT)

+ (void)backButton:(UINavigationItem *)item Col:(UIViewController *)col{
    //左边按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 40, 40);
    [leftButton setImage:[UIImage imageNamed:@"香草园地-发布信息_03@2x"] forState:UIControlStateNormal];
    leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    leftButton.contentEdgeInsets = UIEdgeInsetsMake(0, -4, 0, 0);
    [leftButton addTarget:col action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    item.leftBarButtonItem = leftBarButton;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        col.navigationController.interactivePopGestureRecognizer.enabled = YES;
        col.navigationController.interactivePopGestureRecognizer.delegate = col;
    }
}

+(void)leftNavButton:(UINavigationItem *)item Col:(UIViewController *)col title:(NSString*)title{
    if (!title) {
        title = @"";
    }
    //左边按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, title.length*25, 40);
    [leftButton setTitle:title forState:UIControlStateNormal];
    leftButton.tintColor = [UIColor whiteColor];
    leftButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    leftButton.contentEdgeInsets = UIEdgeInsetsMake(0, -4, 0, 0);

    leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [leftButton addTarget:col action:@selector(leftNavAct) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    item.leftBarButtonItem = leftBarButton;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        col.navigationController.interactivePopGestureRecognizer.enabled = YES;
        col.navigationController.interactivePopGestureRecognizer.delegate = col;
    }
}

+(void)rightNavButton:(UINavigationItem *)item Col:(UIViewController *)col title:(NSString*)title{
    if (!title) {
        title = @"";
    }
    //左边按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, title.length*25, 40);
    [leftButton setTitle:title forState:UIControlStateNormal];
    leftButton.tintColor = [UIColor whiteColor];
    leftButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    leftButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -4);

    leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [leftButton addTarget:col action:@selector(rightNavAct) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    item.rightBarButtonItem = leftBarButton;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        col.navigationController.interactivePopGestureRecognizer.enabled = YES;
        col.navigationController.interactivePopGestureRecognizer.delegate = col;
    }
}
+(void)rightNavButton:(UINavigationItem *)item Col:(UIViewController *)col image:(NSString *)imageNamed
{
    //左边按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 44, 44);
    [leftButton setImage:[UIImage imageNamed:imageNamed] forState:UIControlStateNormal];
    leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    leftButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -4);
    [leftButton addTarget:col action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    item.rightBarButtonItem = leftBarButton;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        col.navigationController.interactivePopGestureRecognizer.enabled = YES;
        col.navigationController.interactivePopGestureRecognizer.delegate = col;
    }

}
@end
